class MigrateDocumentsSecurity < ActiveRecord::Migration
  
  class << self
   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   # Data insert/delete methods
   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    def up
      init_roles
      add_acl_data
    end
    
    def down
      init_roles
      delete_acl_data
    end

    private
      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      # Private data insert/delete methods
      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      def init_roles
        @@admin = Role.find(1)
        #@@user = Role.find(2)
      end

      def add_acl_data
        add_document_management_data
      end

      def add_document_management_data
        sobj = SystemObject.create(:name => "Document Management")
        @@admin.add_system_object(sobj)

        SystemMethod.create(:name => "manage/documents/list", :system_object_id => sobj.id)
        SystemMethod.create(:name => "manage/documents/create", :system_object_id => sobj.id)
        SystemMethod.create(:name => "manage/documents/update", :system_object_id => sobj.id)
        SystemMethod.create(:name => "manage/documents/delete", :system_object_id => sobj.id)
        SystemMethod.create(:name => "manage/documents/manage_files", :system_object_id => sobj.id)
        SystemMethod.create(:name => "manage/documents/add_file", :system_object_id => sobj.id)
        SystemMethod.create(:name => "manage/documents/delete_file", :system_object_id => sobj.id)
        SystemMethod.create(:name => "manage/documents/manage_file_versions", :system_object_id => sobj.id)
        SystemMethod.create(:name => "manage/documents/set_file_version", :system_object_id => sobj.id)
        SystemMethod.create(:name => "manage/documents/delete_file_version", :system_object_id => sobj.id)

      end

      def delete_acl_data
        delete_document_management_data
      end

      def delete_document_management_data
        sobj = SystemObject.find(:first, :conditions => "name = 'Document Management'")
        @@admin.delete_system_object(sobj)
        sobj.destroy
      end

  end #class block
end
